﻿@model TopicModel

@Html.ValidationSummary(false)
@Html.HiddenFor(model => model.Id)

<script>
    $(document).ready(function () {
        bindBootstrapTabSelectEvent('topic-edit');
    });
</script>

<div class="content">
    <div class="form-horizontal">
        <div id="topic-edit" class="nav-tabs-custom">
            <ul class="nav nav-tabs">
                @Html.RenderBootstrapTabHeader("tab-info", @T("Admin.ContentManagement.Topics.Info"), true)
                @Html.RenderBootstrapTabHeader("tab-seo", @T("Admin.Common.SEO"))
            </ul>
            <div class="tab-content">
                @Html.RenderBootstrapTabContent("tab-info", @TabInfo(), true)
                @Html.RenderBootstrapTabContent("tab-seo", @TabSeo())
            </div>
        </div>
    </div>
</div>

@{
    //custom tabs
    var eventMessage = new AdminTabStripCreated(this.Html, "topic-edit");
    EngineContext.Current.Resolve<IEventPublisher>().Publish(eventMessage);
    foreach (var eventBlock in eventMessage.BlocksToRender)
    {
        @eventBlock
    }
}

@*save selected tab name*@
<input type="hidden" id="selected-tab-name" name="selected-tab-name" value="@(Html.GetSelectedTabName())">

@helper TabInfo()
{
    <script type="text/javascript">
        $(document).ready(function () {
            $("#@Html.FieldIdFor(model => model.IsPasswordProtected)").click(togglePassword);
            togglePassword();
        });

        function togglePassword() {
            if ($('#@Html.FieldIdFor(model => model.IsPasswordProtected)').is(':checked')) {
                $('#pnlPasswordEnabled').show();
            } else {
                $('#pnlPasswordEnabled').hide();
            }
        }
    </script>

    <div class="panel-group">
        <div class="panel panel-default">
            <div class="panel-body">
                @(Html.LocalizedEditor<TopicModel, TopicLocalizedModel>("topic-info-localized",
                @<div>
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.Locales[item].Title)
                        </div>
                        <div class="col-md-9">
                            @Html.SDFEditorFor(model => model.Locales[item].Title)
                            @Html.ValidationMessageFor(model => model.Locales[item].Title)
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.Locales[item].Body)
                        </div>
                        <div class="col-md-9">
                            @Html.EditorFor(model => model.Locales[item].Body, "RichEditor")
                            @Html.ValidationMessageFor(model => model.Locales[item].Body)
                        </div>
                    </div>
                    @Html.HiddenFor(model => model.Locales[item].LanguageId)
                </div>
    ,
                @<div>
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.Title)
                        </div>
                        <div class="col-md-9">
                            @Html.SDFEditorFor(model => model.Title)
                            @Html.ValidationMessageFor(model => model.Title)
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.Body)
                        </div>
                        <div class="col-md-9">
                            @Html.EditorFor(x => x.Body, "RichEditor")
                            @Html.ValidationMessageFor(model => model.Body)
                        </div>
                    </div>
                </div>
    ))
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.SDFLabelFor(model => model.SystemName)
                    </div>
                    <div class="col-md-9">
                        @Html.SDFEditorFor(model => model.SystemName)
                        @Html.ValidationMessageFor(model => model.SystemName)
                    </div>
                </div>
                @if (Model.Id > 0)
                {
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.Url)
                        </div>
                        <div class="col-md-9">
                            <a href="@Model.Url"> @Model.Url </a>
                        </div>
                    </div>
                }
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.SDFLabelFor(model => model.Published)
                    </div>
                    <div class="col-md-9">
                        @Html.SDFEditorFor(model => model.Published)
                        @Html.ValidationMessageFor(model => model.Published)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.SDFLabelFor(model => model.IsPasswordProtected)
                    </div>
                    <div class="col-md-9">
                        @Html.SDFEditorFor(model => model.IsPasswordProtected)
                        @Html.ValidationMessageFor(model => model.IsPasswordProtected)
                    </div>
                </div>
                <div class="form-group" id="pnlPasswordEnabled">
                    <div class="col-md-3">
                        @Html.SDFLabelFor(model => model.Password)
                    </div>
                    <div class="col-md-9">
                        @Html.SDFEditorFor(model => model.Password)
                        @Html.ValidationMessageFor(model => model.Password)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.SDFLabelFor(model => model.IncludeInSitemap)
                    </div>
                    <div class="col-md-9">
                        @Html.SDFEditorFor(x => x.IncludeInSitemap)
                        @Html.ValidationMessageFor(model => model.IncludeInSitemap)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.SDFLabelFor(model => model.IncludeInTopMenu)
                    </div>
                    <div class="col-md-9">
                        @Html.SDFEditorFor(x => x.IncludeInTopMenu)
                        @Html.ValidationMessageFor(model => model.IncludeInTopMenu)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.SDFLabelFor(model => model.IncludeInFooterColumn1)
                    </div>
                    <div class="col-md-9">
                        @Html.SDFEditorFor(x => x.IncludeInFooterColumn1)
                        @Html.ValidationMessageFor(model => model.IncludeInFooterColumn1)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.SDFLabelFor(model => model.IncludeInFooterColumn2)
                    </div>
                    <div class="col-md-9">
                        @Html.SDFEditorFor(x => x.IncludeInFooterColumn2)
                        @Html.ValidationMessageFor(model => model.IncludeInFooterColumn2)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.SDFLabelFor(model => model.IncludeInFooterColumn3)
                    </div>
                    <div class="col-md-9">
                        @Html.SDFEditorFor(x => x.IncludeInFooterColumn3)
                        @Html.ValidationMessageFor(model => model.IncludeInFooterColumn3)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.SDFLabelFor(model => model.SelectedCustomerRoleIds)
                    </div>
                    <div class="col-md-9">
                        <div class="row">
                            <div class="col-md-4">
                                @Html.EditorFor(model => model.SelectedCustomerRoleIds, new {SelectList = Model.AvailableCustomerRoles})
                                <script>
                                    $(document).ready(function() {
                                        var rolesIdsInput = $('#@Html.FieldIdFor(model => model.SelectedCustomerRoleIds)').data("kendoMultiSelect");
                                        rolesIdsInput.setOptions({
                                            autoClose: false
                                        });

                                        @if (Model.AvailableCustomerRoles.Count == 0)
                                        {
                                            <text>
                                rolesIdsInput.setOptions({
                                    enable: false,
                                    placeholder: 'No customer roles available'
                                });
                                rolesIdsInput._placeholder();
                                rolesIdsInput._enable();
                                </text>
                                        }
                                    });
                                </script>
                            </div>
                            <div class="col-md-8">
                                @Html.Action("AclDisabledWarning", "Common")
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.SDFLabelFor(model => model.SelectedProjectIds)
                    </div>
                    <div class="col-md-9">
                        <div class="row">
                            <div class="col-md-4">
                                @Html.EditorFor(model => model.SelectedProjectIds, new {SelectList = Model.AvailableProjects})
                                <script>
                                    $(document).ready(function() {
                                        var projectsIdsInput = $('#@Html.FieldIdFor(model => model.SelectedProjectIds)').data("kendoMultiSelect");
                                        projectsIdsInput.setOptions({
                                            autoClose: false
                                        });

                                        @if (Model.AvailableProjects.Count == 0)
                                        {
                                            <text>
                                    projectsIdsInput.setOptions({
                                        enable: false,
                                        placeholder: 'No Projects available'
                                    });
                                    projectsIdsInput._placeholder();
                                    projectsIdsInput._enable();
                                    </text>
                                        }
                                    });
                                </script>
                            </div>
                            <div class="col-md-8">
                                @Html.Action("MultiprojectDisabledWarning", "Common")
                            </div>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.SDFLabelFor(model => model.DisplayOrder)
                    </div>
                    <div class="col-md-9">
                        @Html.SDFEditorFor(x => x.DisplayOrder)
                        @Html.ValidationMessageFor(model => model.DisplayOrder)
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3">
                        @Html.SDFLabelFor(model => model.AccessibleWhenProjectClosed)
                    </div>
                    <div class="col-md-9">
                        @Html.SDFEditorFor(x => x.AccessibleWhenProjectClosed)
                        @Html.ValidationMessageFor(model => model.AccessibleWhenProjectClosed)
                    </div>
                </div>
                <div class="form-group" @(Model.AvailableTopicTemplates.SelectionIsNotPossible() ? Html.Raw("style=\"display:none\"") : null)>
                    <div class="col-md-3">
                        @Html.SDFLabelFor(model => model.TopicTemplateId)
                    </div>
                    <div class="col-md-9">
                        @Html.SDFDropDownListFor(model => model.TopicTemplateId, Model.AvailableTopicTemplates)
                        @Html.ValidationMessageFor(model => model.TopicTemplateId)
                    </div>
                </div>
            </div>
        </div>
    </div>
}

@helper TabSeo()
{
    <div class="panel-group">
        <div class="panel panel-default">
            <div class="panel-body">
                @(Html.LocalizedEditor<TopicModel, TopicLocalizedModel>("topic-seo-localized",
                @<div>
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.Locales[item].MetaKeywords)
                        </div>
                        <div class="col-md-9">
                            @Html.SDFEditorFor(model => model.Locales[item].MetaKeywords)
                            @Html.ValidationMessageFor(model => model.Locales[item].MetaKeywords)
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.Locales[item].MetaDescription)
                        </div>
                        <div class="col-md-9">
                            @Html.SDFTextAreaFor(model => model.Locales[item].MetaDescription)
                            @Html.ValidationMessageFor(model => model.Locales[item].MetaDescription)
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.Locales[item].MetaTitle)
                        </div>
                        <div class="col-md-9">
                            @Html.SDFEditorFor(model => model.Locales[item].MetaTitle)
                            @Html.ValidationMessageFor(model => model.Locales[item].MetaTitle)
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.Locales[item].SeName)
                        </div>
                        <div class="col-md-9">
                            @Html.SDFEditorFor(model => model.Locales[item].SeName)
                            @Html.ValidationMessageFor(model => model.Locales[item].SeName)
                        </div>
                    </div>
                    @Html.HiddenFor(model => model.Locales[item].LanguageId)
                </div>
    ,
                @<div>
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.MetaKeywords)
                        </div>
                        <div class="col-md-9">
                            @Html.SDFEditorFor(x => x.MetaKeywords)
                            @Html.ValidationMessageFor(model => model.MetaKeywords)
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.MetaDescription)
                        </div>
                        <div class="col-md-9">
                            @Html.SDFTextAreaFor(x => x.MetaDescription)
                            @Html.ValidationMessageFor(model => model.MetaDescription)
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.MetaTitle)
                        </div>
                        <div class="col-md-9">
                            @Html.SDFEditorFor(x => x.MetaTitle)
                            @Html.ValidationMessageFor(model => model.MetaTitle)
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.SeName)
                        </div>
                        <div class="col-md-9">
                            @Html.SDFEditorFor(x => x.SeName)
                            @Html.ValidationMessageFor(model => model.SeName)
                        </div>
                    </div>
                </div>))
            </div>
        </div>
    </div>
}
